import { upload } from "@/config/api"
import store from '@/store';

/**
 * 上传图片
 */
export const uploadFilePromise = (url) => {
	return new Promise((resolve, reject) => {
		store.commit("setLoadingShow", true);
		uni.getFileSystemManager().readFile({
			filePath: url,
			encoding: 'base64',
			success: async res => {
				store.commit("setLoadingShow", false);
				let base64 = 'data:image/jpeg;base64,' + res.data
				const url = await upload({ file: base64 })
				if(url) {
					resolve(url)
				}
				reject()
			}, fail: (e) => {
				store.commit("setLoadingShow", false);
				reject()
			}
		})
	})
}
